package com.project.keysManager;

/**
 * Created with IntelliJ IDEA.
 * User: Vandenvin
 * Date: 05.06.14
 * Time: 11:07
 * To change this template use File | Settings | File Templates.
 */

import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;


public class QRCodeGenerator {
    private int width = 400;
    private int height = 400;

    public void generateQRcode(File imageFile, String input) {

        BitMatrix mtx = null;
        QRCodeWriter writer = new QRCodeWriter();
        try {
            mtx = writer.encode(input, BarcodeFormat.QR_CODE, width, height);
        } catch (WriterException e) {
            return;
        }

        if (mtx != null) {
            BufferedImage image = MatrixToImageWriter.toBufferedImage(mtx);
            try {
                ImageIO.write(image, "png", imageFile);
            } catch (IOException e) {
                return;
            }
        }

    }
}